﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class FinanceCenter_AdminDistillMoney_Net2 : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {
        DataTable dt = DAL.Views.V_Users.Select("", "EarningNets2 - EarningNets2Balanced > 0", "isSurrogate desc, [id]");

        if (dt == null)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "数据库连接失败");

            return;
        }

        g.DataSource = dt;
        g.DataBind();
        gPager.Visible = (dt.Rows.Count > 0);
        btnGOAll.Enabled = (dt.Rows.Count > 0);
    }

    protected void g_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {
            double EarningNet2 = ShoveEL._Convert.StrToDouble(e.Item.Cells[8].Text, 0);
            double EarningNet2Balance = ShoveEL._Convert.StrToDouble(e.Item.Cells[9].Text, 0);

            e.Item.Cells[4].Text = (EarningNet2 - EarningNet2Balance).ToString("N");            
        }
    }

    protected void g_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
        long UserID = ShoveEL._Convert.StrToLong(e.Item.Cells[6].Text, -1);

        int ReturnValue = 0;
        string ReturnDescription = "";

        if (e.CommandName == "btnGO")
        {
            if (UserID < 0)
            {
                PublicFunction.GoError(ErrorNumber.Unknow, "数据参数错误", this.GetType().BaseType.FullName);

                return;
            }

            if (DAL.Procedures.P_UserDistillForNets_2.Call(UserID, ref ReturnValue, ref ReturnDescription) < 0)
            {
                ShoveEL._Web.JavaScript.Alert(this.Page, "分红网奖金结算失败");

                return;
            }

            btnGOAll.Enabled = false;
            ShoveEL._Web.JavaScript.Alert(this, "此消费ID分红网奖金结算成功。", "AdminDistillMoney_Net2.aspx");
        }

    }

    protected void gPager_PageWillChange(object Sender, Shove.Web.UI.PageChangeEventArgs e)
    {
        BindData();
    }

    protected void gPager_SortBefore(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
    {
        BindData();
    }

    protected void btnGOAll_Click(object sender, System.EventArgs e)
    {
        if (DAL.Procedures.P_UserDistillAllForNets_2.Call() < 0)
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "分红网奖金结算失败");

            return;
        }

        btnGOAll.Enabled = false;
        ShoveEL._Web.JavaScript.Alert(this, "此消费ID分红网奖金结算成功。", "AdminDistillMoney_Net2.aspx");                
    }


}
